package com.note.config;

import com.alibaba.fastjson.JSONObject;
import com.note.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/6/6 1:45
 * @since JDK 1.8
 */
@ControllerAdvice
@Slf4j
public class GlobalExcetion {

    /**
     * 处理其他异常
     * @param req
     * @param e
     * @return
     */
    @ExceptionHandler(value =Exception.class)
    @ResponseBody
    public JSONObject exceptionHandler(HttpServletRequest req, Exception e){
        log.error("未知异常！原因是:",e);
        return Result.errorInfo(e.getMessage());
    }
}
